package utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author 崔书健
 * @date 2024/7/26
 */
public class Single {
    private static Single single;
    private static Properties properties;

    // 私有构造方法，项目运行期间，仅执行一次
    private Single(){
        String configFile = "database.properties";
        properties = new Properties();
        // 得到当前类的加载器并将配置文件加载到输入流中
        InputStream is = Single.class.getClassLoader().getResourceAsStream(configFile);
        try {
            properties.load(is);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static class SingleHelper{
        private static final Single INSTANCE = new Single();
    }

    // 全局访问点
    public static Single getInstance(){
        single = SingleHelper.INSTANCE;
        return single;
    }

    public String getValue(String key){
        return properties.getProperty(key);
    }

    public static Single test(){
        return single;
    }
}
